package com.enjoyor.health.HGPT.core.service.impl;

import cn.hutool.core.date.LocalDateTimeUtil;
import com.enjoyor.health.HGPT.core.entity.SelftestRecord;
import com.enjoyor.health.HGPT.core.mapper.SelftestRecordMapper;
import com.enjoyor.health.HGPT.core.service.ISelftestRecordService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.google.common.collect.Maps;
import org.springframework.stereotype.Service;

import java.util.Map;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author enjoyor
 * @since 2023-10-18
 */
@Service
public class SelftestRecordServiceImpl extends ServiceImpl<SelftestRecordMapper, SelftestRecord> implements ISelftestRecordService {

    @Override
    public void insertSelftestRecord(SelftestRecord selftestRecord) {
        Map<String, Object> map = Maps.newHashMap();
        map.put("uuid",selftestRecord.getId());
        map.put("userid", selftestRecord.getUserId());
        map.put("record_id", selftestRecord.getRecordId());
        map.put("selftest_id", selftestRecord.getSelftestId());
        map.put("number", selftestRecord.getQuestionNumber());
        map.put("value", selftestRecord.getAbcd());
        map.put("reg_time", LocalDateTimeUtil.format(selftestRecord.getTestTime(), "yyyy-MM-dd HH:mm:ss"));
        map.put("score", selftestRecord.getScore());
        baseMapper.insertSelftestRecord(map);
    }

    @Override
    public int sumScore(String recordId) {
        Map<String,Object> map = Maps.newHashMap();
        map.put("record_id", recordId);
        return baseMapper.sumScore(map);
    }
}
